<template>
  <div class="common-table">
    <el-table
      :data="tableData"
      stripe
      v-loading="config.loading"
      tooltip-effect="dark"
    >
      <el-table-column type="selection" width="50" @click="SelectionChange()">
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        v-for="item in tableLabel"
        :key="item.prop"
        :label="item.label"
      >
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="handleEdit(scope.row)"
            v-show="config.control"
            icon="el-icon-edit"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)"
            icon="el-icon-delete"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pager"
      layout="prev, pager, next"
      :total="config.total"
      pge
      :page-size="config.pageSize"
      @current-change="changePage"
      backgroundge
      :current-page.sync="config.currentPage"
    >
    </el-pagination>
  </div>
</template>

<script>
export default {
  props: {
    //接收数据
    tableData: Array,
    tableLabel: Array,
    config: Object
  },
  methods: {
    handleEdit(row) {
      //向父级传值$emit
      this.$emit("edit", row);
    },
    handleDelete(row) {
      this.$emit("del", row);
    },
    changePage(page) {
      this.$emit("changePage", page);
    },
    SelectionChange() {
      this.$emit("selection-change", this.tableData);
    }
  }
};
</script>
<style lang="scss" scoped>
.common-table {
  background: #fff;
  //height: calc(100% - 63px);
  position: relative;
  .pager {
    position: absolute;

    right: 20px;
  }
}
</style>
